package create.singleton;

/**
 * @author dali
 * @date 2021-07-06 10:59
 * @Description 饿汉2（静态变量快）
 */

public class EHan2 {
    public static void main(String[] args) {
        EHan2 instance1 = getInstance();
        EHan2 instance2 = getInstance();
        System.out.println(instance1 == instance2);//true
    }
    //代码块创建
    static {
        instance = new EHan2();
    }

    //外部不能new
    private EHan2() {

    }
    //创建一个对象实例
    private static EHan2 instance;

    //对外提供接口
    public static EHan2 getInstance() {
        return instance;
    }
}
